<template>
  <div class="user-info-container">
    <el-card class="print-box">
      <el-button type="primary" :loading="printLoading" v-print="printObj">
        {{ $t('msg.userInfo.print') }}</el-button
      >
    </el-card>
    <el-card>
      <div class="user-info-box" id="userInfoBox">
        <!-- 标题 -->
        <h2 class="title">{{ $t('msg.userInfo.title') }}</h2>
        <!-- 头部 -->
        <div class="header">
          <el-descriptions :column="2" border>
            <el-descriptions-item :label="$t('msg.userInfo.name')">{{
              detailData.userName
            }}</el-descriptions-item>
            <el-descriptions-item :label="$t('msg.userInfo.sex')">{{
              detailData.sex === 1 ? '男' : '女'
            }}</el-descriptions-item>
            <el-descriptions-item :label="$t('msg.userInfo.nation')">{{
              detailData.nation
            }}</el-descriptions-item>
            <el-descriptions-item :label="$t('msg.userInfo.mobile')">{{
              detailData.phone
            }}</el-descriptions-item>
            <el-descriptions-item :label="$t('msg.userInfo.province')">{{
              detailData.native_place
            }}</el-descriptions-item>
            <el-descriptions-item :label="$t('msg.userInfo.date')">{{
              $filters.dateFilter(detailData.openTime)
            }}</el-descriptions-item>
            <el-descriptions-item :span="2" :label="$t('msg.userInfo.remark')">
              <el-tag
                class="remark"
                size="small"
                v-for="(item, index) in $filters.jsonFilter(detailData.remark)"
                :key="index"
                >{{ item }}</el-tag
              >
            </el-descriptions-item>
            <el-descriptions-item
              :span="2"
              :label="$t('msg.userInfo.address')"
              >{{ detailData.address }}</el-descriptions-item
            >
          </el-descriptions>
          <el-image class="avatar" :src="detailData.headImg"> </el-image>
        </div>
        <!-- 内容 -->
        <div class="body">
          <el-descriptions :column="1" direction="vertical" border>
            <el-descriptions-item :label="$t('msg.userInfo.experience')">
              <ul>
                <li
                  v-for="(item, index) in $filters.jsonFilter(
                    detailData.experience
                  )"
                  :key="index"
                >
                  <span>
                    {{ $filters.dateFilter(item.startTime, 'YYYY/MM') }}
                    ----
                    {{ $filters.dateFilter(item.endTime, 'YYYY/MM') }}
                  </span>
                  <span>{{ item.title }}</span>
                  <span>{{ item.desc }}</span>
                </li>
              </ul>
            </el-descriptions-item>
            <el-descriptions-item :label="$t('msg.userInfo.major')">{{
              detailData.userName
            }}</el-descriptions-item>
            <el-descriptions-item :label="$t('msg.userInfo.glory')">{{
              detailData.userName
            }}</el-descriptions-item>
          </el-descriptions>
        </div>
        <!-- 尾部 -->
        <div class="foot">{{ $t('msg.userInfo.foot') }}</div>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { defineProps, ref } from 'vue'
import { userDetail } from '@/api/user-manage'
import { watchSwitchLang } from '@/utils/i18n'
const props = defineProps({
  id: {
    type: String,
    required: true
  }
})
const detailData = ref({})
const getUserDetail = async () => {
  detailData.value = await userDetail(props.id)
  console.log(detailData.value)
}
getUserDetail()
watchSwitchLang(getUserDetail)
// 打印相关
const printLoading = ref(false)

const printObj = {
  // 打印区域
  id: 'userInfoBox',
  // 打印标题
  popTitle: 'immoc-vue-element-admin',
  // 打印前
  beforeOpenCallback() {
    printLoading.value = true
  },
  // 执行打印
  openCallback() {
    printLoading.value = false
  }
}
</script>

<style lang="scss" scoped>
.print-box {
  margin-bottom: 20px;
  text-align: right;
}
.user-info-box {
  width: 1024px;
  margin: 0 auto;
  .title {
    text-align: center;
    margin-bottom: 18px;
  }
  .header {
    display: flex;
    ::v-deep .el-descriptions {
      flex-grow: 1;
    }
    .avatar {
      width: 187px;
      box-sizing: border-box;
      padding: 30px 20px;
      border: 1px solid #ebeef5;
      border-left: none;
    }
    .remark {
      margin-right: 12px;
    }
  }
  .body {
    ul {
      list-style: none;
      li {
        span {
          margin-right: 62px;
        }
      }
    }
  }
  .foot {
    margin-top: 42px;
    text-align: right;
  }
}
</style>
